<div id="header">
	<div  id="update-password-form" >
		老密码: <input type="password" id="oldPassword"/>
		新密码: <input type="password" id="newPassword"/>
		重复新密码: <input type="password" id="repeatePassword"/>
		<input type="button" id="update-password-submit" value="修改"/>
		<input type="button" id="update-password-form-exit" value="关闭"/>
		<span id="update-password-error"></span>
	</div>
	<div id="user-info">
		您好, ${currentUser.name} #{if !currentUser.isAdmin}<a class="hand" id="user-toUpadtePassword" >修改密码</a>#{/if}<a href="@@{AuthorityFilter.logout()}">退出</a>
	</div>
</div>
#{if !currentUser.isAdmin}
	<script>
		$(function() {
			DwManager.clickOpenAndClose($("#update-password-form"), $("#user-toUpadtePassword"), $("#update-password-form-exit"));
			//修改密码
			$("#update-password-submit").click(function() {
				var oldPassword = $.trim($("#oldPassword").val());
				var newPassword = $.trim($("#newPassword").val());
				var repeatePassword = $.trim($("#repeatePassword").val());
				if (!oldPassword || !newPassword || !repeatePassword) {
					$("#update-password-error").text("老密码,新密码和重复密码不能为空");
					return;
				}
				if (newPassword != repeatePassword) {
					$("#update-password-error").text("重复密码不一致");
					return;
				}
				$.ajax({
					type : "post",
					url : "@{UserController.updatePassword()}",
					data : {
						oldPassword : oldPassword,
						newPassword : newPassword
					},
					success : function(error) {
						if (error) {
							$("#update-password-error").text(error);
							return;
						} 
						$("#update-password-error").text("");
						$("#update-password-form").find(":password").val("")
						alert("修改成功");
					},
					error : function(e) {
						alert("当前用户不存在");
					}
				});
			});
		})
	</script>
#{/if}
